<?php
/**
 * Created by PhpStorm.
 * User: lee
 * Date: 12/10/18
 * Time: 3:47 PM
 */

class MessageHandler
{
    public static function handle($data)
    {
        if ($data['topic'] === 'coin') {
            $list = [];
            foreach ($data['data'] as $key=>$value) {
                $list[] = [
                    'key' => $key,
                    'value' => $value
                ];
            }
            $msg = [
                'topic' => $data['topic'],
                'data' => $list
            ];
        } else {
            $msg = [
                'topic' => $data['topic'],
                'name' => $data['name'],
                'data' => $data['data']
            ];
        }
        $msg['currency_rate'] = '6.9120';
        //$redis = RedisWrapper::getInstance();
        //$msg['currency_rate'] = $redis->get('currency_rate_cny');
        return json_encode($msg);
    }
}